package com.dianrui.moonfire.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import com.dianrui.moonfire.fragment.FragAgreement;

import java.util.HashMap;

/**
 * desc:我的订单viewPager的适配器
 * Edited by Haipeng.
 */
public class MyAgreementFragmnetAdapter extends FragmentPagerAdapter {
    /**
     * 存储所有的fragment
     */
    public HashMap<Integer, FragAgreement> fragmentMap;
    private Context context;
    private String[] mTitles = new String[]{"全部", "待完成","已完成"};

    public MyAgreementFragmnetAdapter(FragmentManager fm, Context context) {
        super(fm);
        fragmentMap = new HashMap<>();
        this.context = context;
    }

    @Override
    public Fragment getItem(int position) {
        String orderState = null;
        switch (position) {
            case 0:
                orderState="0";
                break;
            case 1:
                orderState="1";
                break;
            case 2:
                orderState="2";
                break;

            default:
                break;
        }
        if (fragmentMap.get(position) == null) {
            FragAgreement fragment = FragAgreement.newInstance(orderState, position);
            fragmentMap.put(position, fragment);
            return fragment;
        } else {
            return fragmentMap.get(position);
        }

    }



    @Override
    public int getCount() {
        return mTitles.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mTitles[position];
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {

    }
}
